<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>
<%@ page import="com.scalar.chiptrack.commons.Constants" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>

<chiptrack:checkLogon sourcePage="/distributorInventory.do?action=editsearch"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();
String userTypeChiptrac = Constants.USER_TYPE_CHIPTRAC + ""; %>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<script language="javascript">
window.onload = init;
var listSize = 0;
function init()
{
    qs_1 = new QuickSearch(document.distributorInventoryForm.product_Id, document.distributorInventoryForm.qs1, false);
    qs_2 = new QuickSearch(document.distributorInventoryForm.distributorId, document.distributorInventoryForm.qs2, false);
}
function searchLots()
{
    document.distributorInventoryForm.action = "<%=chipTracContext%>/distributorInventory.do?action=editsearch";
    document.distributorInventoryForm.submit();
}
function searchLotsOnSubmit()
{
    document.distributorInventoryForm.action = "<%=chipTracContext%>/distributorInventory.do?action=editsearch";
    //document.dieBankReceiveform.submit();
}

function save()
{
    var pa=document.getElementById("message");

    pa.innerHTML                = '';
    var form                    = document.distributorInventoryForm;
    var count1                  = 0;
    
    for( var i=0; i < listSize; i++ )
    {
        if( form['inventoryList['+i+'].checked'].checked == true )
        {
           if ( isNaN( parseInt( form['inventoryList['+i+'].scrapQty'].value ) )
                   && isNaN( parseInt( form['inventoryList['+i+'].additionQty'].value ) ) )
           {
              pa.innerHTML = "<li> Please enter either scrap Qty or additional Qty";
              form['inventoryList['+i+'].scrapQty'].focus();
              return;
           }
           else if ( parseInt( form['inventoryList['+i+'].scrapQty'].value ) > 0 && parseInt( form['inventoryList['+i+'].additionQty'].value ) > 0  )
           {
                pa.innerHTML = "<li> Please enter either scrap Qty or additional Qty";
                form['inventoryList['+i+'].scrapQty'].focus();
                return;
           }
           else if ( parseInt( form['inventoryList['+i+'].scrapQty'].value ) == 0 && parseInt( form['inventoryList['+i+'].additionQty'].value ) == 0  )
           {
                pa.innerHTML = "<li> Please enter either scrap Qty or additional Qty";
                form['inventoryList['+i+'].scrapQty'].focus();
                return;
            }

           count1++;

        }
    }

    if( count1==0 )
	{
		pa.innerHTML = "<li> Please select atleast one lot";
		return;
	}
    document.distributorInventoryForm.action = "<%=chipTracContext%>/distributorInventory.do?action=adjustInventory";
    document.distributorInventoryForm.submit();
}
function enableQtyField( index )
{
    var pa=document.getElementById("message");

    pa.innerHTML                = '';
    var form                    = document.distributorInventoryForm;

    if(form['inventoryList['+index+'].checked'].checked == true )
    {

        form['inventoryList['+index+'].scrapQty'].readOnly = false;
        form['inventoryList['+index+'].additionQty'].readOnly = false;
    }
    else
    {
        form['inventoryList['+index+'].scrapQty'].readOnly = true;
        form['inventoryList['+index+'].additionQty'].readOnly = true;
    }
}

function reset()
{
    document.distributorInventoryForm.reset();
    qs_1.resetQuickSearchCntrl();
    qs_2.resetQuickSearchCntrl();
}

</script>
<!-- Top Header Start-->
<%--<%@ include file="/jsp/includes/header.jsp" %>--%>
<logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/includes/header.jsp" %>
    </logic:equal>
    <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/includes/extHeader.jsp" %>
    </logic:notEqual>
<!-- Top Header End-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
<!-- Side Navigation start -->
<%--<%@ include file="/jsp/operations/dataentryMenu.jsp" %>--%>
    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/operations/dataentryMenu.jsp" %>
    </logic:equal>
    <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/operations/ext_user_dataentryMenu.jsp" %>
    </logic:notEqual>
<!-- end of the side navigations -->
<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">
<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>
<html:form name="distributorInventoryForm" method="POST" onsubmit="javascript:searchLotsOnSubmit();"  action="/distributorInventory?action=editsearch" type="com.scalar.chiptrack.operations.distributor.forms.DistributorInventoryForm" >

<TABLE border="0" width="95%" align=center>
<TR><TD colspan=5 class="NArialW" align="center">Distributor Inventory</TD></TR>
<TR><TD colspan=5>&nbsp;</TD></TR>
<TR><TD colspan=5 class='NArialL'><strong><FONT id="message" color='FF0000'></FONT></strong></TD></TR>
<TR><TD colspan=5>
  <chiptrack:info styleClass="NArialL" />
  <chiptrack:errors styleClass="NArialL" />
  <chiptrack:messages type="info" styleClass="NArialL" />
</TD></TR>

<TR><TD COLSPAN=5>&nbsp;</TD></TR>
<TR><TD align="left">
<TABLE  border="0" width="80%" cellpadding="1" cellspacing="1">

    <tr>    <TD width="10%" class="NArialL">&nbsp;</TD>
            <td class="NArialL" width='20%'>
            Quick Search:
            </td>
            <td class="NArialL" width='20%'>
            <input type="text" name="qs1" class="txfield" size='30' onkeyup='quickSearch(qs_1)'/>
            </td>
            <TD width="15%" class="NArialL">Quick Search:</TD>
            <TD width="15%" class="NArialL"><input type="text" name="qs2" class="txfield" size='30' onkeyup='quickSearch(qs_2)'/></TD>
    </tr>
    <TR>
        <logic:present name="partNumbersList" scope="request">
            <TD width="10%" class="NArialL">&nbsp;</TD>
            <TD width="20%" class="NArialL">Product Name:</TD>
            <TD width="20%" class="NArialL">
                <html:select property="product_Id"  name="distributorInventoryForm" styleClass="txfield">
                    <html:option value="0">All Products</html:option>
                    <html:options collection="partNumbersList" property="value" labelProperty="label"/>
                </html:select>
            </TD>
        </logic:present>
        <logic:notPresent name="partNumbersList" scope="request">
            <TD width="10%" class="NArialL">&nbsp;</TD>
            <TD width="20%" class="NArialL">&nbsp;</TD>
            <TD width="20%" class="NArialL">&nbsp;</TD>
       </logic:notPresent>
        <logic:present name="distributorList" scope="request">
            <TD width="15%"><font class="NArialL">&nbsp;&nbsp;Distributor Name:</font></TD>
            <TD width="15%" class="NArialL">
                <html:select property="distributorId" name="distributorInventoryForm" styleClass="txfield">
                    <html:options collection="distributorList" property="value" labelProperty="label"/>
                </html:select>
            </TD>
        </logic:present>
        <logic:notPresent name="distributorList" scope="request">
            <TD width="15%" class="NArialL">&nbsp;</TD>
            <TD width="15%" class="NArialL">&nbsp;</TD>
        </logic:notPresent>
    </TR>
    <TR>
        <TD COLSPAN="5"><IMG SRC="<%=chipTracContext%>/jsp/includes/images/spacer.gif" HEIGHT=20></TD>
    </TR>

    <TR>
       <td colspan="5" align="center">
            <a href="javascript:searchLots()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif" width="53" height="17" onmouseover="window.status='Click to Search for Diebank Receive Lots';return true" onmouseout="window.status='';return true" title="Click to Search for Diebank Receive Lots"/></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="javascript:reset()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
      </td>
    </TR>

    </TABLE></TD></TR>
    <nested:present property="inventoryList">
    <nested:size id="LotsSize" property="inventoryList"/>
    <logic:greaterThan name="LotsSize" value="0">
     <TR>
        <td colspan="5">
            <table width="100%" align="left" cellpadding="2" cellspacing="2" border="0">
                <tr>
                <td colspan="11"class='NArialL'><font class='NArialS'><font color='blue'>[Click on Select checkbox to update Distributor Inventory]</font></font></td>
            </tr>
            <tr bgcolor="#993333" align = "center">
                <td width="3%" class='NArialL'><font color="#FFFFFF">Select </font></td>
                <td width="10%" class='NArialL'><font color="#FFFFFF">Part No# </font></td>
                <td width="10%" class='NArialL' nowrap><font color="#FFFFFF">Lot No#</font></td>
                <td width="12%" class='NArialL'><font color="#FFFFFF">Dist. Name</font></td>
                <td width="5%" class='NArialL'><font color="#FFFFFF">Date Code</font></td>
                <td width="10%" class='NArialL'><font color="#FFFFFF">Available Qty</font></td>

                <td width="10%" class='NArialL'><font color="#FFFFFF">Scrap Qty</font></td>
                <td width="10%" class='NArialL'><font color="#FFFFFF">Add Qty</font></td>
             </tr>
            
            <nested:size id="listSize" property="inventoryList"/>
            <nested:iterate id="distlotInfo" property="inventoryList" indexId="iterateIdx" type = "com.scalar.chiptrack.operations.distributor.DistributorInventory">
            <% String click = "enableQtyField('" + iterateIdx.intValue() + "')"; %>
            <tr bgcolor='<%=iterateIdx.intValue() % 2 == 0 ? "#FFFFEE" : "#DEE1E2"%>'>
                <td width ="3%" align="center" ><font class='NArialL'><nested:checkbox  name="distlotInfo" property = "checked" onclick="<%= click %>"/> </td>
                <td><font class='NArialL'><nested:write name="distlotInfo" property ="partNumber"/></font></td>
                <td><font class='NArialL'><nested:write name="distlotInfo" property ="lot_number"/></font></td>
                <td><font class='NArialL'><nested:write name="distlotInfo" property ="distributorName"/></font></td>
                <td><font class='NArialL'><nested:write name="distlotInfo" property ="dateCode"/></font></td>
                <td align="right"><font class='NArialL'><nested:write name="distlotInfo" property ="qty_available"/></font></td>
                <nested:hidden name="distlotInfo" property="distributorId"/>
                <nested:hidden name="distlotInfo" property="productId"/>
                <nested:hidden name="distlotInfo" property="lot_id"/>

                <td align="center"><input type="text" name="inventoryList[<%=iterateIdx.intValue()%>].scrapQty" size ="12" value="" readonly="true" onkeypress="javascript:allowInteger()" class="valuetxfield"/>
                 </td>
                <td align="center"><input type="text" name="inventoryList[<%=iterateIdx.intValue()%>].additionQty" size ="12" value="" readonly="true" onkeypress="javascript:allowInteger()" class="valuetxfield"/>
                 </td>
            </tr>
             </nested:iterate>
             <script type="text/javascript">
               listSize = <%=listSize.intValue()%>;
            </script>
            <%--<tr bgcolor='#DEE1E2'>
                <td colspan="8" class='NArialL'><input type="checkbox" name="select_bottom" onClick = "javascript:setSelectAllIds(this)">&nbsp;&nbsp Select All</td>
            </tr>--%>
             <TR>
                <TD COLSPAN="10"><IMG SRC="<%=chipTracContext%>/jsp/includes/images/spacer.gif" HEIGHT=20></TD>
            </TR>
            <tr>
               <td align="center" colspan ="10">
                    <a href="javascript:save()" onmouseover="window.status='Click here to update distributor Inventory';return true" onmouseout="window.status='';return true" title="Click here to update distributor Inventory"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:reset()" onmouseover="window.status='Click here to Reset the distributor Inventory';return true" onmouseout="window.status='';return true" title="Click here to Reset the distributor Inventory"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>
                </td>
            </tr>
          </table></td></tr>
        </logic:greaterThan>
    </nested:present>

 </TABLE>
</html:form>
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</HTML>

<%--
<%
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
%>--%>
